package com.xgame.server.dbtool;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xgame.server.db.mapper.GamecfgMapper;
import com.xgame.server.db.model.Gamecfg;
import com.xgame.server.netty.proto.Game;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class GamecfgCsTool {
    @Resource
    private GamecfgMapper gamecfgMapper;

    //插入玩家记录
    public Integer insertGameCfg(Game.GameCfgCS data) throws Exception {
        Integer result = new Integer(0);

        Gamecfg account = new Gamecfg();
        account.setAccount(data.getAccount());
        account.setPlayerId(data.getPlayerID());
        account.setIdentity(data.getIdentify());
        account.setFirstRecord(data.getFirstRecord());
        account.setLastRecord(data.getLastRecord());
        account.setIsEntered(data.getIsEntered() ? 1 : 0);
        account.setOpFlag(new Long(data.getOpflag()));

        return gamecfgMapper.insert(account);
    }

    //更新玩家记录
    public Integer updateGameCfg(Game.GameCfgCS data) throws Exception {
        EntityWrapper<Gamecfg> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", data.getAccount());

        Gamecfg account = new Gamecfg();
        account.setAccount(data.getAccount());
        account.setPlayerId(data.getPlayerID());
        account.setIdentity(data.getIdentify());
        account.setFirstRecord(data.getFirstRecord());
        account.setLastRecord(data.getLastRecord());
        account.setIsEntered(data.getIsEntered() ? 1 : 0);
        account.setOpFlag(new Long(data.getOpflag()));

        return gamecfgMapper.update(account, userWrapper);
    }

    //删除记录
    public Integer deleteGameCfg(Game.GameCfgCS data) throws Exception {
        EntityWrapper<Gamecfg> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", data.getAccount());

        return gamecfgMapper.delete(userWrapper);
    }

    //查询记录
    public List<Gamecfg> selectGameCfg(String account) throws Exception {
        EntityWrapper<Gamecfg> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return gamecfgMapper.selectList(userWrapper);
    }
}
